package dao;

import com.sun.org.apache.xerces.internal.impl.xs.models.XSCMUniOp;
import entity.Orgnazition;
import service.OrgnazitionService;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class InstitutionalDao extends BaseDao {
    Orgnazition orgnazition = null;
        //显示全部的方法
        public List<Orgnazition> show(){
            List<Orgnazition> list = new ArrayList<>();
            super.init();
            conn = super.getConnection();
            try {
                pstmt = conn.prepareStatement("select * from orgnazition ORDER BY createDete desc");
                rs = pstmt.executeQuery();
                while (rs.next()){
                    orgnazition = new Orgnazition();
                    orgnazition.setId(rs.getInt("id"));
                    orgnazition.setCreateDete(rs.getString("createDete"));
                    orgnazition.setName(rs.getString("name"));
                    orgnazition.setPrincipaName(rs.getString("principaName"));
                    orgnazition.setStatus(rs.getInt("status"));
                    list.add(orgnazition);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }

            return list;
        }
        //添加方法
        public int add(Orgnazition orgnazition){
            int add = 0;
            super.init();
            conn = super.getConnection();
            try {
                pstmt = conn.prepareStatement("INSERT orgnazition(name, principaName,status,createDete) VALUES (?,?,0,?)");
                pstmt.setString(1,orgnazition.getName());
                pstmt.setString(2,orgnazition.getPrincipaName());
                pstmt.setString(3,orgnazition.getCreateDete());
                add = pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return add;
        }
        //修改
        public int update(int status,String name){
            int count = 0;
            super.init();
            conn = super.getConnection();
            try{
                pstmt = conn.prepareStatement("update orgnazition set status=? where principaName=?");
                pstmt.setInt(1,status);
                pstmt.setString(2,name);
                count = pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return count;
        }

}
